﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using HexChessBoard;

namespace HexChessBoard.PlayerComponents
{
    /// <summary>
    /// Player controlled by local input.
    /// </summary>
    internal class PlayerLocal : Player
    {
        
        Vector3 RootWhitePosition;
        Vector3 RootBlackPosition;

        // XBox move timer
        const int timeForMove = 150;    // time between registering thumbstick entries
        int timeSinceMove = 0;      

        public PlayerLocal(PlayerIndex index, PieceColor pieceColor, Board board, Vector2 screenSize, Viewport viewport) : base (board, pieceColor)
        {
            playerIndex = index;
            if (board.Variant == GameVariant.Glinsky || board.Variant == GameVariant.McCooey)
            {
                RootWhitePosition = new Vector3(board.Tiles[40].Position.X, 450, board.Tiles[40].Position.Z + 180);
                RootBlackPosition = new Vector3(board.Tiles[50].Position.X, 450, board.Tiles[50].Position.Z - 180);
            }
            else
            {
                RootWhitePosition = new Vector3(board.Tiles[30].Position.X, 450, board.Tiles[30].Position.Z + 200);
                RootBlackPosition = new Vector3(board.Tiles[39].Position.X, 450, board.Tiles[39].Position.Z - 200);
            }

            this.PlayerCamera = new SimpleCamera();

            switch (pieceColor)
            {
                case PieceColor.White:
                    switch (board.Variant)
                    {
                        case GameVariant.Glinsky:
                            this.PlayerCamera.Create(RootWhitePosition, board.Tiles[44].Position, screenSize, viewport, SimpleCamera.ViewportLocation.FullScreen);
                            SelectedTile = board.Tiles[44];
                            break;
                        case GameVariant.McCooey:
                            this.PlayerCamera.Create(RootWhitePosition, board.Tiles[44].Position, screenSize, viewport, SimpleCamera.ViewportLocation.FullScreen);
                            SelectedTile = board.Tiles[43];
                            break;
                        case GameVariant.Shafran:
                            this.PlayerCamera.Create(RootWhitePosition, board.Tiles[34].Position, screenSize, viewport, SimpleCamera.ViewportLocation.FullScreen);
                            SelectedTile = board.Tiles[31];
                            break;
                    }
                    break;
                case PieceColor.Black:
                    switch (board.Variant)
                    {
                        case GameVariant.Glinsky:
                            this.PlayerCamera.Create(RootBlackPosition, board.Tiles[46].Position, screenSize, viewport, SimpleCamera.ViewportLocation.FullScreen);
                            SelectedTile = board.Tiles[46];
                            break;
                        case GameVariant.McCooey:
                            this.PlayerCamera.Create(RootBlackPosition, board.Tiles[46].Position, screenSize, viewport, SimpleCamera.ViewportLocation.FullScreen);
                            SelectedTile = board.Tiles[47];
                            break;
                        case GameVariant.Shafran:
                            this.PlayerCamera.Create(RootBlackPosition, board.Tiles[35].Position, screenSize, viewport, SimpleCamera.ViewportLocation.FullScreen);
                            SelectedTile = board.Tiles[38];
                            break;
                    }
                    break;
            }
        }

        public override void Draw(GameTime gameTime)
        {
            throw new NotImplementedException();
        }

        public override void Update(Board board, GameTime gameTime)
        {
            this.PlayerCamera.Update(gameTime);
        }

        public override void HandleInput(InputState inputState, GameTime gameTime)
        {
            // Reset XBox timer.
            if (timeSinceMove >= timeForMove)
                timeSinceMove = 0;
            else
                timeSinceMove += gameTime.ElapsedGameTime.Milliseconds;

            // Handle keyboard input
            switch (this.Side)
            {
                case PieceColor.White:
                    // Move up
                    if (inputState.IsNewKeyPress(Keys.NumPad5, this.playerIndex) || (inputState.IsThumbstickRotation2(this.playerIndex) && timeSinceMove == 0))
                    {
                        if (SelectedTile != null && SelectedTile.Neighbors[0] != null)
                        {
                            SelectedTile = SelectedTile.Neighbors[0];
                        }
                    }
                    if (inputState.IsNewKeyPress(Keys.NumPad6, this.playerIndex) || (inputState.IsThumbstickRotation1(this.playerIndex) && timeSinceMove == 0))
                    {
                        if (SelectedTile != null && SelectedTile.Neighbors[2] != null)
                        {
                            SelectedTile = SelectedTile.Neighbors[2];
                        }
                    }
                    if (inputState.IsNewKeyPress(Keys.NumPad3, this.playerIndex) || (inputState.IsThumbstickRotation4(this.playerIndex) && timeSinceMove == 0))
                    {
                        if (SelectedTile != null && SelectedTile.Neighbors[4] != null)
                        {
                            SelectedTile = SelectedTile.Neighbors[4];
                        }
                    }
                    if (inputState.IsNewKeyPress(Keys.NumPad2, this.playerIndex) || (inputState.IsThumbstickRotation5(this.playerIndex) && timeSinceMove == 0))
                    {
                        if (SelectedTile != null && SelectedTile.Neighbors[1] != null)
                        {
                            SelectedTile = SelectedTile.Neighbors[1];
                        }
                    }
                    if (inputState.IsNewKeyPress(Keys.NumPad1, this.playerIndex) || (inputState.IsThumbstickRotation6(this.playerIndex) && timeSinceMove == 0))
                    {
                        if (SelectedTile != null && SelectedTile.Neighbors[5] != null)
                        {
                            SelectedTile = SelectedTile.Neighbors[5];
                        }
                    }
                    if (inputState.IsNewKeyPress(Keys.NumPad4, this.playerIndex) || (inputState.IsThumbstickRotation3(this.playerIndex) && timeSinceMove == 0))
                    {
                        if (SelectedTile != null && SelectedTile.Neighbors[3] != null)
                        {
                            SelectedTile = SelectedTile.Neighbors[3];
                        }
                    }
                    if ((inputState.IsNewKeyPress(Keys.X, this.playerIndex) || inputState.IsNewButtonPress(Buttons.X, this.playerIndex))
                        && PlayerBoard.CanCastleWhiteQueen >= 1)
                    {
                        PlayerBoard.BoardPositions.Clear();
                        PlayerBoard.moveSound.Play();
                        BoardSupport.MovePiece(ref PlayerBoard, ref PlayerBoard.Tiles[0], ref PlayerBoard.Tiles[21]);
                        BoardSupport.MovePiece(ref PlayerBoard, ref PlayerBoard.Tiles[30], ref PlayerBoard.Tiles[13]);
                        BoardSupport.EndTurn(ref PlayerBoard, PieceType.None);

                        if (PlayerBoard.BlackCheckmate || PlayerBoard.WhiteCheckmate || PlayerBoard.Stalemate)
                            PlayerBoard.endSound.Play();
                        else if (PlayerBoard.WhiteCheck || PlayerBoard.BlackCheck)
                            PlayerBoard.checkSound.Play();

                        UpgradingPieces = false;
                        SourceTile = null;
                    }
                    if ((inputState.IsNewKeyPress(Keys.L, this.playerIndex) || inputState.IsNewButtonPress(Buttons.LeftShoulder, this.playerIndex))
                        && PlayerBoard.CanCastleWhiteQueen == 2)
                    {
                        PlayerBoard.BoardPositions.Clear();
                        PlayerBoard.moveSound.Play();
                        BoardSupport.MovePiece(ref PlayerBoard, ref PlayerBoard.Tiles[0], ref PlayerBoard.Tiles[13]);
                        BoardSupport.MovePiece(ref PlayerBoard, ref PlayerBoard.Tiles[30], ref PlayerBoard.Tiles[6]);
                        BoardSupport.EndTurn(ref PlayerBoard, PieceType.None);

                        if (PlayerBoard.BlackCheckmate || PlayerBoard.WhiteCheckmate || PlayerBoard.Stalemate)
                            PlayerBoard.endSound.Play();
                        else if (PlayerBoard.WhiteCheck || PlayerBoard.BlackCheck)
                            PlayerBoard.checkSound.Play();

                        UpgradingPieces = false;
                        SourceTile = null;
                    }
                    if ((inputState.IsNewKeyPress(Keys.Y, this.playerIndex) || inputState.IsNewButtonPress(Buttons.Y, this.playerIndex))
                        && PlayerBoard.CanCastleWhiteBishop >= 1)
                    {
                        PlayerBoard.BoardPositions.Clear();
                        PlayerBoard.moveSound.Play();
                        BoardSupport.MovePiece(ref PlayerBoard, ref PlayerBoard.Tiles[64], ref PlayerBoard.Tiles[40]);
                        BoardSupport.MovePiece(ref PlayerBoard, ref PlayerBoard.Tiles[30], ref PlayerBoard.Tiles[49]);
                        BoardSupport.EndTurn(ref PlayerBoard, PieceType.None);

                        if (PlayerBoard.BlackCheckmate || PlayerBoard.WhiteCheckmate || PlayerBoard.Stalemate)
                            PlayerBoard.endSound.Play();
                        else if (PlayerBoard.WhiteCheck || PlayerBoard.BlackCheck)
                            PlayerBoard.checkSound.Play();

                        UpgradingPieces = false;
                        SourceTile = null;
                    }
                    if ((inputState.IsNewKeyPress(Keys.R, this.playerIndex) || inputState.IsNewButtonPress(Buttons.RightShoulder, this.playerIndex))
                        && PlayerBoard.CanCastleWhiteBishop == 2)
                    {
                        PlayerBoard.BoardPositions.Clear();
                        PlayerBoard.moveSound.Play();
                        BoardSupport.MovePiece(ref PlayerBoard, ref PlayerBoard.Tiles[64], ref PlayerBoard.Tiles[49]);
                        BoardSupport.MovePiece(ref PlayerBoard, ref PlayerBoard.Tiles[30], ref PlayerBoard.Tiles[57]);
                        BoardSupport.EndTurn(ref PlayerBoard, PieceType.None);

                        if (PlayerBoard.BlackCheckmate || PlayerBoard.WhiteCheckmate || PlayerBoard.Stalemate)
                            PlayerBoard.endSound.Play();
                        else if (PlayerBoard.WhiteCheck || PlayerBoard.BlackCheck)
                            PlayerBoard.checkSound.Play();

                        UpgradingPieces = false;
                        SourceTile = null;
                    }
                    if (inputState.IsNewKeyPress(Keys.OemPeriod, this.playerIndex) || inputState.IsNewButtonPress(Buttons.RightThumbstickRight, this.playerIndex))
                    {
                        PlayerCamera.RotateDesiredPositionAroundLookatY(0.7f);
                        break;
                    }
                    if (inputState.IsNewKeyPressUp(Keys.OemPeriod, this.playerIndex) || inputState.IsNewButtonPressUp(Buttons.RightThumbstickRight, this.playerIndex))
                    {
                        PlayerCamera.DesiredPosition = RootWhitePosition;
                        break;
                    }
                    if (inputState.IsNewKeyPress(Keys.OemComma, this.playerIndex) || inputState.IsNewButtonPress(Buttons.RightThumbstickLeft, this.playerIndex))
                    {
                        PlayerCamera.RotateDesiredPositionAroundLookatY(-0.7f);
                        break;
                    }
                    if (inputState.IsNewKeyPressUp(Keys.OemComma, this.playerIndex) || inputState.IsNewButtonPressUp(Buttons.RightThumbstickLeft, this.playerIndex))
                    {
                        PlayerCamera.DesiredPosition = RootWhitePosition;
                        break;
                    }
                    if (inputState.IsNewKeyPress(Keys.L, this.playerIndex) || inputState.IsNewButtonPress(Buttons.RightThumbstickUp, this.playerIndex))
                    {
                        PlayerCamera.RotateDesiredPositionAroundLookatX(-0.4f);
                        PlayerCamera.DesiredPosition.Y += 250;
                        PlayerCamera.DesiredPosition.Z += 160;
                        break;
                    }
                    if (inputState.IsNewKeyPressUp(Keys.L, this.playerIndex) || inputState.IsNewButtonPressUp(Buttons.RightThumbstickUp, this.playerIndex))
                    {
                        PlayerCamera.DesiredPosition = RootWhitePosition;
                        break;
                    }
                    break;
                case PieceColor.Black:
                    // Move up
                    if (inputState.IsNewKeyPress(Keys.NumPad5, this.playerIndex) || (inputState.IsThumbstickRotation2(this.playerIndex) && timeSinceMove == 0))
                    {
                        if (SelectedTile != null && SelectedTile.Neighbors[1] != null)
                        {
                            SelectedTile = SelectedTile.Neighbors[1];
                        }
                    }
                    if (inputState.IsNewKeyPress(Keys.NumPad6, this.playerIndex) || (inputState.IsThumbstickRotation1(this.playerIndex) && timeSinceMove == 0))
                    {
                        if (SelectedTile != null && SelectedTile.Neighbors[5] != null)
                        {
                            SelectedTile = SelectedTile.Neighbors[5];
                        }
                    }
                    if (inputState.IsNewKeyPress(Keys.NumPad3, this.playerIndex) || (inputState.IsThumbstickRotation4(this.playerIndex) && timeSinceMove == 0))
                    {
                        if (SelectedTile != null && SelectedTile.Neighbors[3] != null)
                        {
                            SelectedTile = SelectedTile.Neighbors[3];
                        }
                    }
                    if (inputState.IsNewKeyPress(Keys.NumPad2, this.playerIndex) || (inputState.IsThumbstickRotation5(this.playerIndex) && timeSinceMove == 0))
                    {
                        if (SelectedTile != null && SelectedTile.Neighbors[0] != null)
                        {
                            SelectedTile = SelectedTile.Neighbors[0];
                        }
                    }
                    if (inputState.IsNewKeyPress(Keys.NumPad1, this.playerIndex) || (inputState.IsThumbstickRotation6(this.playerIndex) && timeSinceMove == 0))
                    {
                        if (SelectedTile != null && SelectedTile.Neighbors[2] != null)
                        {
                            SelectedTile = SelectedTile.Neighbors[2];
                        }
                    }
                    if (inputState.IsNewKeyPress(Keys.NumPad4, this.playerIndex) || (inputState.IsThumbstickRotation3(this.playerIndex) && timeSinceMove == 0))
                    {
                        if (SelectedTile != null && SelectedTile.Neighbors[4] != null)
                        {
                            SelectedTile = SelectedTile.Neighbors[4];
                        }
                    }
                    if ((inputState.IsNewKeyPress(Keys.X, this.playerIndex) || inputState.IsNewButtonPress(Buttons.X, this.playerIndex))
                        && PlayerBoard.CanCastleBlackQueen >= 1)
                    {
                        PlayerBoard.BoardPositions.Clear();
                        PlayerBoard.moveSound.Play();
                        BoardSupport.MovePiece(ref PlayerBoard, ref PlayerBoard.Tiles[69], ref PlayerBoard.Tiles[48]);
                        BoardSupport.MovePiece(ref PlayerBoard, ref PlayerBoard.Tiles[39], ref PlayerBoard.Tiles[56]);
                        BoardSupport.EndTurn(ref PlayerBoard, PieceType.None);

                        if (PlayerBoard.BlackCheckmate || PlayerBoard.WhiteCheckmate || PlayerBoard.Stalemate)
                            PlayerBoard.endSound.Play();
                        else if (PlayerBoard.WhiteCheck || PlayerBoard.BlackCheck)
                            PlayerBoard.checkSound.Play();

                        UpgradingPieces = false;
                        SourceTile = null;
                    }
                    if ((inputState.IsNewKeyPress(Keys.L, this.playerIndex) || inputState.IsNewButtonPress(Buttons.LeftShoulder, this.playerIndex))
                        && PlayerBoard.CanCastleBlackQueen == 2)
                    {
                        PlayerBoard.BoardPositions.Clear();
                        PlayerBoard.moveSound.Play();
                        BoardSupport.MovePiece(ref PlayerBoard, ref PlayerBoard.Tiles[69], ref PlayerBoard.Tiles[56]);
                        BoardSupport.MovePiece(ref PlayerBoard, ref PlayerBoard.Tiles[39], ref PlayerBoard.Tiles[63]);
                        BoardSupport.EndTurn(ref PlayerBoard, PieceType.None);

                        if (PlayerBoard.BlackCheckmate || PlayerBoard.WhiteCheckmate || PlayerBoard.Stalemate)
                            PlayerBoard.endSound.Play();
                        else if (PlayerBoard.WhiteCheck || PlayerBoard.BlackCheck)
                            PlayerBoard.checkSound.Play();

                        UpgradingPieces = false;
                        SourceTile = null;
                    }
                    if ((inputState.IsNewKeyPress(Keys.Y, this.playerIndex) || inputState.IsNewButtonPress(Buttons.Y, this.playerIndex))
                        && PlayerBoard.CanCastleBlackBishop >= 1)
                    {
                        PlayerBoard.BoardPositions.Clear();
                        PlayerBoard.moveSound.Play();
                        BoardSupport.MovePiece(ref PlayerBoard, ref PlayerBoard.Tiles[5], ref PlayerBoard.Tiles[29]);
                        BoardSupport.MovePiece(ref PlayerBoard, ref PlayerBoard.Tiles[39], ref PlayerBoard.Tiles[20]);
                        BoardSupport.EndTurn(ref PlayerBoard, PieceType.None);

                        if (PlayerBoard.BlackCheckmate || PlayerBoard.WhiteCheckmate || PlayerBoard.Stalemate)
                            PlayerBoard.endSound.Play();
                        else if (PlayerBoard.WhiteCheck || PlayerBoard.BlackCheck)
                            PlayerBoard.checkSound.Play();

                        UpgradingPieces = false;
                        SourceTile = null;
                    }
                    if ((inputState.IsNewKeyPress(Keys.R, this.playerIndex) || inputState.IsNewButtonPress(Buttons.RightShoulder, this.playerIndex))
                        && PlayerBoard.CanCastleBlackBishop == 2)
                    {
                        PlayerBoard.BoardPositions.Clear();
                        PlayerBoard.moveSound.Play();
                        BoardSupport.MovePiece(ref PlayerBoard, ref PlayerBoard.Tiles[5], ref PlayerBoard.Tiles[20]);
                        BoardSupport.MovePiece(ref PlayerBoard, ref PlayerBoard.Tiles[39], ref PlayerBoard.Tiles[12]);
                        BoardSupport.EndTurn(ref PlayerBoard, PieceType.None);

                        if (PlayerBoard.BlackCheckmate || PlayerBoard.WhiteCheckmate || PlayerBoard.Stalemate)
                            PlayerBoard.endSound.Play();
                        else if (PlayerBoard.WhiteCheck || PlayerBoard.BlackCheck)
                            PlayerBoard.checkSound.Play();

                        UpgradingPieces = false;
                        SourceTile = null;
                    }
                    if (inputState.IsNewKeyPress(Keys.OemPeriod, this.playerIndex) || inputState.IsNewButtonPress(Buttons.RightThumbstickRight, this.playerIndex))
                    {
                        PlayerCamera.RotateDesiredPositionAroundLookatY(0.7f);
                        break;
                    }
                    if (inputState.IsNewKeyPressUp(Keys.OemPeriod, this.playerIndex) || inputState.IsNewButtonPressUp(Buttons.RightThumbstickRight, this.playerIndex))
                    {
                        PlayerCamera.DesiredPosition = RootBlackPosition;
                        break;
                    }
                    if (inputState.IsNewKeyPress(Keys.OemComma, this.playerIndex) || inputState.IsNewButtonPress(Buttons.RightThumbstickLeft, this.playerIndex))
                    {
                        PlayerCamera.RotateDesiredPositionAroundLookatY(-0.7f);
                        break;
                    }
                    if (inputState.IsNewKeyPressUp(Keys.OemComma, this.playerIndex) || inputState.IsNewButtonPressUp(Buttons.RightThumbstickLeft, this.playerIndex))
                    {
                        PlayerCamera.DesiredPosition = RootBlackPosition;
                        break;
                    }
                    if (inputState.IsNewKeyPress(Keys.L, this.playerIndex) || inputState.IsNewButtonPress(Buttons.RightThumbstickUp, this.playerIndex))
                    {
                        PlayerCamera.RotateDesiredPositionAroundLookatX(0.4f);
                        PlayerCamera.DesiredPosition.Y += 250;
                        PlayerCamera.DesiredPosition.Z -= 160;
                        break;
                    }
                    if (inputState.IsNewKeyPressUp(Keys.L, this.playerIndex) || inputState.IsNewButtonPressUp(Buttons.RightThumbstickUp, this.playerIndex))
                    {
                        PlayerCamera.DesiredPosition = RootBlackPosition;
                        break;
                    }
                    break;
            }

            if (inputState.IsNewButtonPress(Buttons.DPadUp, playerIndex) || inputState.IsNewKeyPress(Keys.Up, playerIndex))
            {
                displayAvailable++;
                if (displayAvailable > 2)
                    displayAvailable = 0;
            }
            if (inputState.IsNewButtonPress(Buttons.DPadDown, playerIndex) || inputState.IsNewKeyPress(Keys.Down, playerIndex))
            {
                displayMode++;
                if (displayMode > 2)
                    displayMode = 0;
            }

            // if we are upgrading pieces, don't go through move tile piece, wait for upgrade piece input then end turn.
            if (!UpgradingPieces)
            {
                if (inputState.IsNewKeyPress(Keys.Enter, this.playerIndex) || inputState.IsNewButtonPress(Buttons.A, this.playerIndex))
                {
                    // If there is a  SourceTile, we are moving if the tile is blank, 
                    //      capturing if it is not and side == side, selecting if side != side;
                    if (SourceTile != null)
                    {
                        // unselect if clicking multiple times on same tile
                        if (SourceTile == SelectedTile)
                            SourceTile = null;
                        else if (SourceTile.AvailableMoves.Contains(SelectedTile))
                        {
                            if (!PlayerBoard.BlackCheckmate && !PlayerBoard.WhiteCheckmate && !PlayerBoard.Stalemate)
                            {
                                if ((SourceTile.WasEnPassant && SourceTile.Piece == PieceType.Pawn && SourceTile.file != SelectedTile.file) || SelectedTile.Piece != PieceType.None)
                                    PlayerBoard.captureSound.Play();
                                else
                                    PlayerBoard.moveSound.Play();

                                if (PlayerBoard.FiftyMoveCount == 50 || PlayerBoard.FiftyMoveCount == 75 || PlayerBoard.FiftyMoveCount > 94 || PlayerBoard.RepeatedMoveCount == 2 || PlayerBoard.RepeatedMoveCount == 3)
                                    PlayerBoard.timerSound.Play();
                            }

                            // clear repeated move amounts to reduce overhead
                            // Capture pieces from opposing sides
                            if (SelectedTile.Piece != PieceType.None || (SelectedTile.Piece == PieceType.None && SourceTile.Piece == PieceType.Pawn && SourceTile.WasEnPassant))
                                PlayerBoard.BoardPositions.Clear();

                            BoardSupport.MovePiece(ref PlayerBoard, ref SourceTile, ref SelectedTile);
                            UpgradingPieces = BoardSupport.CanUpgradePawns(PlayerBoard);
                            if (!UpgradingPieces)
                            {
                                BoardSupport.EndTurn(ref PlayerBoard, PieceType.None);

                                if (PlayerBoard.BlackCheckmate || PlayerBoard.WhiteCheckmate || PlayerBoard.Stalemate)
                                    PlayerBoard.endSound.Play();
                                else if (PlayerBoard.WhiteCheck || PlayerBoard.BlackCheck)
                                    PlayerBoard.checkSound.Play();

                                UpgradingPieces = false;
                                SourceTile = null;
                            }
                            // todo if checkmate, say game over, show icon, allow "a" to restart, "b" to go to main menu
                        }
                    }
                    // Else, we are making it our SourceTile.
                    else if (SelectedTile.Piece != PieceType.None && SelectedTile.Side == this.Side)
                        SourceTile = SelectedTile;
                }
                else if (inputState.IsNewKeyPress(Keys.Back, this.playerIndex) || inputState.IsNewButtonPress(Buttons.B, this.playerIndex))
                {
                    // Remove any selected tiles
                    SourceTile = null;
                }
            }
            // IF we are upgrading pieces, wait until input to upgrade the type and end turn
            else if (inputState.IsNewKeyPress(Keys.A, this.playerIndex) || inputState.IsNewKeyPress(Keys.B, this.playerIndex) ||
                     inputState.IsNewKeyPress(Keys.X, this.playerIndex) || inputState.IsNewKeyPress(Keys.Y, this.playerIndex) ||
                     inputState.IsNewButtonPress(Buttons.A, this.playerIndex) || inputState.IsNewButtonPress(Buttons.B, this.playerIndex) ||
                     inputState.IsNewButtonPress(Buttons.X, this.playerIndex) || inputState.IsNewButtonPress(Buttons.Y, this.playerIndex))
            {
                PieceType upgradePiece = PieceType.None;
                if (inputState.IsNewKeyPress(Keys.A, this.playerIndex))
                    upgradePiece = PieceType.Queen;
                else if (inputState.IsNewKeyPress(Keys.B, this.playerIndex))
                    upgradePiece = PieceType.Bishop;
                else if (inputState.IsNewKeyPress(Keys.X, this.playerIndex))
                    upgradePiece = PieceType.Rook;
                else if (inputState.IsNewKeyPress(Keys.Y, this.playerIndex))
                    upgradePiece = PieceType.Knight;

                BoardSupport.EndTurn(ref PlayerBoard, upgradePiece);
                UpgradingPieces = false;
                SourceTile = null;
            }
        }
    }
}
